import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test {

    public static void main(String[] args) {

    }
    /*
      三数之和
     */
    public List<List<Integer>> threeSum(int[] nums) {
        Arrays.sort(nums);
        int n = nums.length;
        int i = 0;
        List<List<Integer>> ret = new ArrayList<>();
        while(i < n) {
            if(nums[i] > 0) {
                break;
            }
            int left = i+1;
            int right = n-1;
            int target = -nums[i];
            while(left < right) {
                int sum = nums[left]+nums[right];
                if(sum > target) {
                    right--;
                }else if(sum < target) {
                    left++;
                }else {
                    List<Integer> list = new ArrayList<>();
                    list.add(nums[i]);
                    list.add(nums[left]);
                    list.add(nums[right]);
                    ret.add(list);
                    left++;
                    right--;
                    while(left < right && nums[left] == nums[left-1]) {
                        left++;
                    }
                    while(left < right && nums[right] == nums[right+1]) {
                        right--;
                    }
                }
            }
            i++;
            while(i < n && nums[i] == nums[i-1]) {
                i++;
            }
        }
        return ret;
    }
    /**
     * 两数之和
     */
    public int[] twoSum(int[] price, int target) {
        int left = 0;
        int right = price.length-1;
        while(left < right) {
            if(price[left]+price[right]>target) {
                right--;
            }else if(price[left]+price[right]<target) {
                left++;
            }else {
                break;
            }
        }
        int[] arr = {price[left],price[right]};
        return arr;
    }



}
